//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    public class IconSet: IOfficeXmlSerializable
    {
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("iconSet"))
            {
                Type = c.GetOptionalEnum("iconSet", IconSetType.ThreeTrafficLights1);
                Percent = c.GetOptionalBoolean("percent", true);
                Reverse = c.GetOptionalBoolean("reverse", false);
                ValueVisible = c.GetOptionalBoolean("showValue", true);
                Objects.Clear();
                while (c.ReaderLocalName == "cfvo")
                {
                    Objects.Add(c.ReadElement<ConditionalFormatValueObject>());
                }
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("iconSet"))
            {
                c.SetOptionalEnum("iconSet", Type, IconSetType.ThreeTrafficLights1);
                c.SetOptionalBoolean("percent", Percent, true);
                c.SetOptionalBoolean("reverse", Reverse, false);
                c.SetOptionalBoolean("showValue", ValueVisible, true);
                foreach (ConditionalFormatValueObject o in Objects)
                    c.WriteElement(o);
            }
        }

        #endregion

        private bool reverse;

        public bool Reverse
        {
            get { return reverse; }
            set { reverse = value; }
        }
	

        private bool percent;

        public bool Percent
        {
            get { return percent; }
            set { percent = value; }
        }
	

        private bool showValue;

        public bool ValueVisible
        {
            get { return showValue; }
            set { showValue = value; }
        }
	

        private IconSetType type;

        public IconSetType Type
        {
            get { return type; }
            set { type = value; }
        }
	

        private readonly List<ConditionalFormatValueObject> _objects = new List<ConditionalFormatValueObject>();
        public List<ConditionalFormatValueObject> Objects
        {
            get { return _objects; }
        }

        public int IconCount{get
        {
            switch (this.Type)
            { case IconSetType.FiveArrows:
                    return 5;
                case IconSetType.FiveArrowsGray:
                    return 5;
                case IconSetType.FiveQuarters:
                    return 5;
                case IconSetType.FiveRating:
                    return 5;
                case IconSetType.FourArrows:
                    return 4
                        ;
                case IconSetType.FourArrowsGray:
                    return 4;
                case IconSetType.FourRating:
                    return 4;
                case IconSetType.FourRedToBlack:
                    return 4;
                case IconSetType.FourTrafficLights:
                    return 4;
                case IconSetType.ThreeArrows:
                    return 3;
                case IconSetType.ThreeArrowsGray:
                    return 3;
                case IconSetType.ThreeFlags:
                    return 3;
                case IconSetType.ThreeSigns:
                    return 3;
                case IconSetType.ThreeSymbols:
                    return 3;
                case IconSetType.ThreeSymbols2:
                    return 3;
                case IconSetType.ThreeTrafficLights1:
                    return 3;
                case IconSetType.ThreeTrafficLights2:
                    return 3;
                default: throw new NotSupportedException();
            }
        }
        }
    }
}
